/*
 * Copyright(C) 2010 Luvina Software Company
 *
 * LoginSession.java, Oct 29, 2010 ntmhuong
 */
package net.luvina.manageuser.managedbean;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import net.luvina.manageuser.dto.LoginDto;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * LoginSession
 * @author ntmhuong
 *
 */
@Component("loginSession")
@Scope("session")
public class LoginSession implements Serializable {
    private static final long serialVersionUID = 1L;
    private static final int SESSION_EXPIRE_SPAN = 10; //[Minute]
    private boolean         login;
    private String          loginId;

    /**
     * コンストラクタ�?��報初期�?
     */
    public LoginSession() {
        this.clear();
    }

    /**
     * �??初期�?
     */
    public void clear() {
        this.login                      = false;
        this.loginId              = "";
    }

    /**
     * ユーザ認証�??生�?
     *
     * @param loginDto
     */
    public void createLoginInfo(LoginDto loginDto) {
        this.login               = true;
        this.loginId             = loginDto.getLoginId();

    }

    /**
     * ログインの有効期限チェ�?��
     *
     * @return boolean ログイン有効期限�?��??rue=有効期限�? false=有効期限�?��??
     */
    public boolean checkLoginExpire() {
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.MINUTE, SESSION_EXPIRE_SPAN * -1);
        return cal.getTime().before(new Date());
    }

	/**
	 * @return the login
	 */
	public boolean isLogin() {
		return login;
	}

	/**
	 * @param login the login to set
	 */
	public void setLogin(boolean login) {
		this.login = login;
	}

	/**
	 * @return the loginId
	 */
	public String getLoginId() {
		return loginId;
	}

	/**
	 * @param loginId the loginId to set
	 */
	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}
}
